package jp.ne.hatena.d.digitalsoul.warikan.roles

import jp.ne.hatena.d.digitalsoul.warikan.math._
import jp.ne.hatena.d.digitalsoul.warikan.models._

trait Accountant {
	
	var sum:Int
	
	var allot:Map[String, Allot]
		
	def adjust(pieMaker:PieMaker, slopeId:Int) = {
		val pie = pieMaker.createPie(slopeId)
		this.allot = calculateAllot(pie)
	}
	
	private def calculateAllot(pie:Map[String, Fraction]):Map[String, Allot] = {
		var tempAllot = Map[String, Allot]()
		for (it <- pie) {
			val name = it._1
			val payment:Int = pie(name) * sum
			tempAllot += (name -> new Allot(name, payment))			
		}
		tempAllot
	}
			
}